home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_ciel_client_observer.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  12.1 KB  |  522 lines

  1. unit ntc_ciel_client_observer;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     ExtCtrls,
  37.     inifiles,
  38.     ComCtrls,
  39.  
  40.     ntc_ciel_client_form;
  41.  
  42. const
  43.     max_latitude_degrees=90;
  44.     max_longitude_degrees=360;
  45.  
  46. type
  47.     Tscope_observer = class(tform)
  48.         observer_panel: TPanel;
  49.         observatory_group: TGroupBox;
  50.         latitude_label: TLabel;
  51.         longitude_label: TLabel;
  52.         time_zone_label: TLabel;
  53.         time_zone_edit: TEdit;
  54.     longitude_degrees_edit: TEdit;
  55.         longitude_degrees_up_down: TUpDown;
  56.     longitude_minutes_edit: TEdit;
  57.     longitude_minutes_up_down: TUpDown;
  58.     longitude_seconds_edit: TEdit;
  59.     longitude_seconds_up_down: TUpDown;
  60.         move_degrees_label: TLabel;
  61.     move_minutes_label: TLabel;
  62.     move_seconds_label: TLabel;
  63.     latitude_degrees_edit: TEdit;
  64.     latitude_degrees_up_down: TUpDown;
  65.         latitude_minutes_edit: TEdit;
  66.         latitude_minutes_up_down: TUpDown;
  67.         latitude_seconds_edit: TEdit;
  68.         latitude_seconds_up_down: TUpDown;
  69.         time_zone_up_down: TUpDown;
  70.         hours_label: TLabel;
  71.  
  72.         { form handling }
  73.         procedure formcreate(
  74.             Sender:TObject);
  75.  
  76.         { configuration }
  77.         procedure load_settings;
  78.  
  79.         procedure save_settings;
  80.  
  81.         { events }
  82.         procedure latitude_edit_boxes;
  83.         procedure longitude_edit_boxes;
  84.  
  85.         procedure latitude_degrees_editKeyPress(
  86.                     Sender: TObject;
  87.             var Key: Char);
  88.  
  89.         procedure latitude_minutes_editKeyPress(
  90.                     Sender: TObject;
  91.             var Key: Char);
  92.  
  93.         procedure latitude_seconds_editKeyPress(
  94.                     Sender: TObject;
  95.             var Key: Char);
  96.  
  97.         procedure latitude_degrees_up_downChanging(
  98.                     Sender: TObject;
  99.             var AllowChange: Boolean);
  100.  
  101.         procedure latitude_minutes_up_downChanging(
  102.                     Sender: TObject;
  103.             var AllowChange: Boolean);
  104.  
  105.         procedure latitude_seconds_up_downChanging(
  106.                     Sender: TObject;
  107.             var AllowChange: Boolean);
  108.  
  109.         procedure longitude_degrees_editKeyPress(
  110.                     Sender: TObject;
  111.             var Key: Char);
  112.  
  113.         procedure longitude_minutes_editKeyPress(
  114.                     Sender: TObject;
  115.             var Key: Char);
  116.  
  117.         procedure longitude_seconds_editKeyPress(
  118.                     Sender: TObject;
  119.             var Key: Char);
  120.  
  121.         procedure longitude_degrees_up_downChanging(
  122.                     Sender: TObject;
  123.             var AllowChange: Boolean);
  124.  
  125.         procedure longitude_minutes_up_downChanging(
  126.                     Sender: TObject;
  127.             var AllowChange: Boolean);
  128.  
  129.         procedure longitude_seconds_up_downChanging(
  130.                     Sender: TObject;
  131.             var AllowChange: Boolean);
  132.  
  133.         procedure time_zone_editChange(
  134.             Sender: TObject);
  135.  
  136.         procedure FormShow(
  137.             Sender: TObject);
  138.  
  139.         procedure adjust;
  140.  
  141.         procedure check_activate(
  142.             Sender: TObject);
  143.  
  144.         procedure form_close_query(
  145.                     Sender: TObject;
  146.             var CanClose: Boolean);
  147.  
  148.         procedure time_zone_up_downClick(
  149.             Sender: TObject;
  150.             Button: TUDBtnType);
  151.  
  152.     private
  153.         { Private declarations }
  154.         latitude_degrees_updating,
  155.         latitude_minutes_updating,
  156.         latitude_seconds_updating,
  157.         longitude_degrees_updating,
  158.         longitude_minutes_updating,
  159.         longitude_seconds_updating,
  160.         time_zone_updating:boolean;
  161.     public
  162.         { Public declarations }
  163.         { observer location }
  164.         latitude,
  165.         longitude:double;
  166.         degrees_ra,
  167.         degrees_dec,
  168.         degrees_az,
  169.         degrees_alt:double;
  170.         time_zone:integer;
  171.         date_time:tdatetime;
  172.         { configuration }
  173.         dimensions:dimensions_record;
  174.         { location }
  175.         latitude_degrees,
  176.         latitude_minutes,
  177.         latitude_seconds,
  178.         longitude_degrees,
  179.         longitude_minutes,
  180.         longitude_seconds:extended;
  181.  
  182.         Function set_observer(
  183.             lat,
  184.             long,
  185.             zone:double;
  186.             date_time:Tdatetime)
  187.             :boolean;
  188.  
  189.         { events }
  190.         procedure check_visible_and_show_hide(
  191.             sender:tobject);
  192.  
  193.         procedure hide_form;
  194.         procedure show_form;
  195.     end;
  196.  
  197. var
  198.     scope_observer: Tscope_observer;
  199.  
  200. implementation
  201.  
  202. uses
  203.     ntc_ciel_client_control;
  204.  
  205. {$R *.dfm}
  206.  
  207.     { -------------
  208.         form handling
  209.         ------------- }
  210.  
  211. procedure tscope_observer.formcreate(
  212.     Sender:TObject);
  213. begin
  214.     time_zone:=strtointdef(time_zone_edit.text,0);
  215.     latitude_degrees_updating:=false;
  216.     latitude_minutes_updating:=false;
  217.     latitude_seconds_updating:=false;
  218.     longitude_degrees_updating:=false;
  219.     longitude_minutes_updating:=false;
  220.     longitude_seconds_updating:=false;
  221.     time_zone_updating:=false;
  222.     load_settings;
  223.     case scope_type of
  224.         lx200_type:observatory_group.visible:=true;
  225.         autostar_type:observatory_group.visible:=true;
  226.     end;
  227.     visible:=false;
  228. end;
  229.  
  230. Function tscope_observer.set_observer(
  231.     lat,
  232.     long,
  233.     zone:double;
  234.     date_time:Tdatetime)
  235.     :boolean;
  236. begin
  237.     result:=true;
  238. end;
  239.  
  240.     { -------------
  241.         configuration
  242.         ------------- }
  243.  
  244. procedure tscope_observer.load_settings;
  245. begin
  246.     ini_file:=tinifile.create(application_path+'ciel.ini');
  247.     with ini_file do
  248.         begin
  249.             longitude:=readfloat('observer','longitude',4);
  250.             latitude:=readfloat('observer','latitude',51);
  251.             { form }
  252.             scope.get_dimensions(scope_observer,@dimensions,'observer',ini_file);
  253.             left:=dimensions.form_left;
  254.             top:=dimensions.form_top;
  255.             visible:=readbool('observer','visible',false);
  256.         end;
  257.     ini_file.free;
  258. end;
  259.  
  260. procedure tscope_observer.save_settings;
  261. begin
  262.     with ini_file,dimensions do
  263.         begin
  264.             writefloat('observer','longitude',longitude);
  265.             writefloat('observer','latitude',latitude);
  266.             { form }
  267.             scope.find_vdu(scope_observer,@dimensions);
  268.             scope.write_dimensions(@dimensions,left,top,'observer',ini_file);
  269.             writebool('observer','visible',visible);
  270.         end;
  271. end;
  272.  
  273.     { ---------
  274.         utilities
  275.         --------- }
  276.  
  277. procedure tscope_observer.latitude_edit_boxes;
  278. begin
  279.     latitude_degrees:=strtofloatdef(latitude_degrees_edit.text,latitude_degrees);
  280.     latitude_minutes:=strtofloatdef(latitude_minutes_edit.text,latitude_minutes);
  281.     latitude_seconds:=strtofloatdef(latitude_seconds_edit.text,latitude_seconds);
  282.     scope_control.normalise(
  283.         max_latitude_degrees,latitude_degrees,latitude_minutes,latitude_seconds);
  284.     latitude:=(latitude_seconds/60+latitude_minutes)/60+latitude_degrees;
  285.     latitude_degrees_edit.text:=floattostr(latitude_degrees);
  286.     latitude_minutes_edit.Text:=floattostr(latitude_minutes);
  287.     latitude_seconds_edit.text:=floattostr(latitude_seconds);
  288.     latitude_degrees_up_down.position:=trunc(latitude_degrees);
  289.     latitude_minutes_up_down.position:=trunc(latitude_minutes);
  290.     latitude_seconds_up_down.position:=trunc(latitude_seconds);
  291. end;
  292.  
  293. procedure tscope_observer.longitude_edit_boxes;
  294. begin
  295.     longitude_degrees:=strtofloatdef(longitude_degrees_edit.text,longitude_degrees);
  296.     longitude_minutes:=strtofloatdef(longitude_minutes_edit.text,longitude_minutes);
  297.     longitude_seconds:=strtofloatdef(longitude_seconds_edit.text,longitude_seconds);
  298.     scope_control.normalise(
  299.         max_longitude_degrees,longitude_degrees,longitude_minutes,longitude_seconds);
  300.     longitude:=(longitude_seconds/60+longitude_minutes)/60+longitude_degrees;
  301.     longitude_degrees_edit.text:=floattostr(longitude_degrees);
  302.     longitude_minutes_edit.Text:=floattostr(longitude_minutes);
  303.     longitude_seconds_edit.text:=floattostr(longitude_seconds);
  304.     longitude_degrees_up_down.position:=trunc(longitude_degrees);
  305.     longitude_minutes_up_down.position:=trunc(longitude_minutes);
  306.     longitude_seconds_up_down.position:=trunc(longitude_seconds);
  307. end;
  308.  
  309.     { ------
  310.         events
  311.         ------ }
  312.  
  313. procedure tscope_observer.latitude_degrees_editKeyPress(
  314.             Sender: TObject;
  315.     var Key: Char);
  316. begin
  317.     if key=cr then
  318.         latitude_edit_boxes;
  319. end;
  320.  
  321. procedure tscope_observer.latitude_minutes_editKeyPress(
  322.             Sender: TObject;
  323.     var Key: Char);
  324. begin
  325.     if key=cr then
  326.         latitude_edit_boxes;
  327. end;
  328.  
  329. procedure tscope_observer.latitude_seconds_editKeyPress(
  330.             Sender: TObject;
  331.     var Key: Char);
  332. begin
  333.     if key=cr then
  334.         latitude_edit_boxes;
  335. end;
  336.  
  337. procedure tscope_observer.latitude_degrees_up_downChanging(
  338.             Sender: TObject;
  339.     var AllowChange: Boolean);
  340. begin
  341.     if not latitude_degrees_updating then
  342.         begin
  343.             latitude_degrees_updating:=true;
  344.             latitude_edit_boxes;
  345.             latitude_degrees_updating:=false;
  346.         end;
  347. end;
  348.  
  349. procedure tscope_observer.latitude_minutes_up_downChanging(
  350.             Sender: TObject;
  351.     var AllowChange: Boolean);
  352. begin
  353.     if not latitude_minutes_updating then
  354.         begin
  355.             latitude_minutes_updating:=true;
  356.             latitude_edit_boxes;
  357.             latitude_minutes_updating:=false;
  358.         end;
  359. end;
  360.  
  361. procedure tscope_observer.latitude_seconds_up_downChanging(
  362.             Sender: TObject;
  363.     var AllowChange: Boolean);
  364. begin
  365.     if not latitude_seconds_updating then
  366.         begin
  367.             latitude_seconds_updating:=true;
  368.             latitude_edit_boxes;
  369.             latitude_seconds_updating:=false;
  370.         end;
  371. end;
  372.  
  373. procedure tscope_observer.longitude_degrees_editKeyPress(
  374.             Sender: TObject;
  375.     var Key: Char);
  376. begin
  377.     if key=cr then
  378.         longitude_edit_boxes;
  379. end;
  380.  
  381. procedure tscope_observer.longitude_minutes_editKeyPress(
  382.             Sender: TObject;
  383.     var Key: Char);
  384. begin
  385.     if key=cr then
  386.         longitude_edit_boxes;
  387. end;
  388.  
  389. procedure tscope_observer.longitude_seconds_editKeyPress(
  390.             Sender: TObject;
  391.     var Key: Char);
  392. begin
  393.     if key=cr then
  394.         longitude_edit_boxes;
  395. end;
  396.  
  397. procedure tscope_observer.longitude_degrees_up_downChanging(
  398.             Sender: TObject;
  399.     var AllowChange: Boolean);
  400. begin
  401.     if not longitude_degrees_updating then
  402.         begin
  403.             longitude_degrees_updating:=true;
  404.             longitude_edit_boxes;
  405.             longitude_degrees_updating:=false;
  406.         end;
  407. end;
  408.  
  409. procedure tscope_observer.longitude_minutes_up_downChanging(
  410.             Sender: TObject;
  411.     var AllowChange: Boolean);
  412. begin
  413.     if not longitude_minutes_updating then
  414.         begin
  415.             longitude_minutes_updating:=true;
  416.             longitude_edit_boxes;
  417.             longitude_minutes_updating:=false;
  418.         end;
  419. end;
  420.  
  421. procedure tscope_observer.longitude_seconds_up_downChanging(
  422.             Sender: TObject;
  423.     var AllowChange: Boolean);
  424. begin
  425.     if not longitude_seconds_updating then
  426.         begin
  427.             longitude_seconds_updating:=true;
  428.             longitude_edit_boxes;
  429.             longitude_seconds_updating:=false;
  430.         end;
  431. end;
  432.  
  433. procedure Tscope_observer.time_zone_editChange(
  434.     Sender: TObject);
  435. begin
  436.     time_zone:=strtointdef(time_zone_edit.text,0);
  437. end;
  438.  
  439. procedure Tscope_observer.FormShow(
  440.     Sender: TObject);
  441. begin
  442.     with dimensions do
  443.         begin
  444.             top:=form_top;
  445.             left:=form_left;
  446.         end;
  447. end;
  448.  
  449. procedure tscope_observer.adjust;
  450. begin
  451.     with dimensions do
  452.         begin
  453.             form_top:=trunc(form_top/last_screen_height*current_height);
  454.             form_left:=trunc(form_left/last_screen_width*current_width);
  455.         end;
  456.     if visible then
  457.         show;
  458. end;
  459.  
  460. procedure tscope_observer.check_visible_and_show_hide(
  461.     sender:tobject);
  462. begin
  463.     if visible then
  464.         hide_form
  465.     else
  466.         show_form;
  467.     scope.show_hide(sender,visible);
  468. end;
  469.  
  470. procedure tscope_observer.hide_form;
  471. begin
  472.     with dimensions do
  473.         begin
  474.             form_top:=top;
  475.             form_left:=left;
  476.         end;
  477.     Visible:=false;
  478.     formstyle:=fsnormal;
  479. end;
  480.  
  481. procedure tscope_observer.show_form;
  482. begin
  483.     formstyle:=fsstayontop;
  484.     Visible:=true;
  485. end;
  486.  
  487. procedure Tscope_observer.check_activate(
  488.     Sender: TObject);
  489. begin
  490.     scope.form_activate(scope_observer,@dimensions);
  491. end;
  492.  
  493. procedure Tscope_observer.form_close_query(
  494.             Sender: TObject;
  495.     var CanClose: Boolean);
  496. begin
  497.     visible:=false;
  498.     with dimensions do
  499.         begin
  500.             form_top:=top;
  501.             form_left:=left;
  502.         end;
  503.     if ciel_closing then
  504.         canclose:=true
  505.     else
  506.         canclose:=false;
  507. end;
  508.  
  509. procedure Tscope_observer.time_zone_up_downClick(
  510.     Sender: TObject;
  511.     Button: TUDBtnType);
  512. begin
  513.     if not time_zone_updating then
  514.         begin
  515.             time_zone_updating:=true;
  516.             time_zone:=strtointdef(time_zone_edit.text,0);
  517.             time_zone_updating:=false;
  518.         end;
  519. end;
  520.  
  521. end.
  522.